/*
 * Created on 2021年11月29日
 * 
 * Copyright(c) YuZhou Big Data Laboratory CO.,Ltd, 2022.  All rights reserved.
 *
 *******************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ******************************************************************************/
package org.pentaho.di.ui.spoon.cluster;

import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Image;
import org.yzbdl.lanius.core.quartz.entity.TaskCronInfo;
import org.pentaho.di.i18n.BaseMessages;
import org.pentaho.di.ui.spoon.Spoon;

/**
 * 这个方法主要是作为"标签器"的作用来用的.
 * "标签器"将一个个实体对象的字段变量分别取出然后系那是在TableViewer的各个列中.
 * 实现对应的接口
 * 
 * @author yzbdl@yzbdl.ac.cn
 * @version 1.0
 * @since 1.0
 */
public class TableViewerLabelProvider implements ITableLabelProvider {
    @Override
    public Image getColumnImage(Object element, int columnIndex) {
        return null;// 这个和getColumnText()不同的是,这个方法可以返回一个null值.
    }

    /**
     * 由此方法决定数据记录在表格的每一列是显示什么文字
     * @param element 实体类对象
     * @param columnIndex 列号，0是第一列
     * @return 返回值一定要避免NULL值,否则出错
     */
    @Override
    public String getColumnText(Object element, int columnIndex) {
        TaskCronInfo taskCronInfo = (TaskCronInfo)element;
        if (!"delete".equals(taskCronInfo.getType())) {
            if (columnIndex == 0) {
                if ("job".equals(taskCronInfo.getType())) {
                    return BaseMessages.getString(Spoon.class, "Spoon.Menubar.File.NewJob");
                } else {
                    return BaseMessages.getString(Spoon.class, "Spoon.STRING_TRANSFORMATION");
                }
            }

            if (columnIndex == 1) {
                return taskCronInfo.getTaskName();
            }

            if (columnIndex == 2) {
                return taskCronInfo.getIsEnable()
                    ? BaseMessages.getString(Spoon.class, "SpoonSlave.QuartzManage.online")
                    : BaseMessages.getString(Spoon.class, "SpoonSlave.QuartzManage.offline");
            }

            if (columnIndex == 3) {
                return taskCronInfo.getCronExpr();
            }

            if (columnIndex == 4) {
                return taskCronInfo.getDate();
            }
        }
        return "";
    }

    @Override
    public void addListener(ILabelProviderListener listener) {}

    @Override
    public void dispose() {}

    @Override
    public boolean isLabelProperty(Object element, String property) {
        return false;
    }

    @Override
    public void removeListener(ILabelProviderListener listener) {}
}